//随机验证码
function verifyCode(n){
	let count = n || 4;
	let arr = ["q","a","z","x","s","w","e","d","c","v","f","r","t","g","b","n","h","y","u","j","m","k","i","o","l","p","0","1","2","3","4","5","6","7","8","9"];
	let result = "";
	for(let i = 0; i < count ;i++){
		var index = Math.floor(Math.random() * arr.length)
		result = result + arr[index];
	}
	return result;
}
//刷新验证码
$("#ma").click(function(){
	$("#ma").html(verifyCode())
})

$(function(){
	$("#tijiao").click(function(){
		if($("#username").val()==""||$("#password").val()==""){
			alert("不能为空哦")
			return;
		}
		let reg=/^[1][3,4,5,7,8][0-9]{9}$/;
		if(!reg.test($("#username").val())){
			alert("请输入正确的电话号码")
			return;
		}
		/* let reg2 = /^\d{6,16}$/;
		if(!reg2.test($("#password").val())){
			alert("请输入六到十六位密码")
			return;
		} */
		if($("#password").val()!==$("#password2").val()){
			alert("两次密码输入不一致，请重新输入")
			return;
		}
	$.post(
		"zhuce.php",
		{
			"username":$("#username").val(),
			"password":$("#password").val()
		},
		function(data){
			if(data=="success"){
				alert("恭喜您，注册成功！请登录");
				//保存cookie：
				// saveCookie("username",$("#username").val(),15);
					location.href="denglu.html";
			}else if(data=="erro"){
			   alert("注册失败");
			}else{
				alert("服务器出错了！");
			}
			
		}
	);
});

      })